<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Customer</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/jsrender.js"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            if(localStorage.getItem("token")==null){
                window.location.href="login.html"
            }
          //获取护士id
            var nid
            if(localStorage.getItem("position")==1){
            	nid = 0
            	list()
            }
            else{$.ajax({
               		 url:GC.bctx + "customers/getnid",//后端请求映射路径
               		 type:"GET",
               		 data:{useraccount:localStorage.getItem("account")},
              	 	 headers: {"Authorization": localStorage.getItem("token")},
              	 	 success:function (r) {
                	  	  if(r.successed){
                 	 	      nid = r.data
                 	 	    list()
                 	 	  }else{
                  		      alert(r.message)
                 		  }
               		 }
            	})
            }
            //请求所有入住记录(可查看的客户)
            function list(){
            	$.ajax({
                    url:GC.bctx + "customers/listLivein/"+nid,//后端请求映射路径
                    type:"GET",
                    headers: {"Authorization": localStorage.getItem("token")},
                    success:function (r) {
                        if(r.successed){
                            //jsrender模板渲染
                            $("#livein").html($("#liveinTemplate").render(r.data))
                        }else{
                            alert(r.message)
                        }
                    }
                })
            }
            
            //响应入住登记
            $("#new").click(function() {
                window.location.href="livein.html"
            })
            //form提交组合查询
            $("form").submit(function(){
                //异步提交
                //数据验证交给后端数据检验
                //ajax
                $.ajax({
                    url:GC.bctx + "customers/findLivein",
                    type:"GET",
                    data:$("form").serialize(),//需要配上属性name：name="id" name="name"
                    headers: {"Authorization": localStorage.getItem("token")},
                    success:function(r){
                        if(r.successed){
                            //成功了渲染
                            $("#livein").html($("#liveinTemplate").render(r.data))
                        }else{
                            alert(r.message)
                        }
                    }
                })
                //阻止表单正常提交
                return false;
            })
        })
    </script>
    <script id="liveinTemplate" type="text/x-jsrender">
	<tr align="center">
		<td>{{:customerid}}</td>
		<td>{{:bookingid}}</td>
		<td>{{:bedid}}</td>
		<td>{{:liveindate}}</td>
		<td>{{:expectedliveoutdate}}</td>
		<td>{{:actuallyliveoutdate}}</td>

	</tr>
    </script>
</head>
<body>
    <button id="new" class="btn btn-primary">新增入住登记</button>
    <form action="find" class="container-fluid">
        <label>客户id：<input name="customerid" type="text"/></label>
        <label>客户姓名：<input name="customername" type="text"/></label>
        <input type="submit" value="查 询"/>
        <input type="reset" value="重 置"/>
    </form>
    <table class="table table-bordered">
        <tr>
            <th>客户id</th>
            <th>订单id</th>
            <th>床位</th>
            <th>入住日期</th>
            <th>预期离院日期</th>
            <th>实际离院日期</th>
        </tr>
        <tbody id="livein"></tbody>
    </table>
</body>
</html>